<?php

namespace yphp;
/**
 * Class View
 * @package yphp
 * 视图类
 */
class View extends Compile
{

    function construct($file)
    {
        $this->path = $this->changePath($file);
        $this->view_path = $this->getview();
        if(!is_file($this->view_path)) throw new \Exception($file . '视图文件不存在');
        $this->compile_path = $this->getCompile($this->path);
        if (!$this->isCompileUse($this->compile_path, $this->view_path)) {
            # 如果无效，进行编译
            DealFile::writeFile($this->compile_path, $this->compile(file_get_contents($this->view_path)), true);
            DealFile::delDir(CACHE_HTML_PATH . $this->path, true);
        }
    }

    // 获取视图文件编译路径
    protected  function getCompile($path)
    {
        return CACHE_COMPILE_PATH . $path . '.html';
    }

    // 获取静态文件路径
    protected function getHtml($path)
    {
        return CACHE_HTML_PATH . $path . DS . Safe::en(serialize(Request::instance()->path())) . '.html';
    }

}